﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BaseViewModel.cs" company="Spenta Consulting">
//   (c) Copyright 2011
// </copyright>
// <summary>
//   Base view model
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Spenta.StreetCare.Silverlight.MVVM.ViewModels
{
    #region Using Directives

    using System.ComponentModel;
    using System.Windows;

    using Spenta.StreetCare.MVC.Services.RIA;
    using Spenta.StreetCare.Silverlight.GeocodeService;
    using Spenta.StreetCare.Silverlight.Resources;

    using StreetCareAPI;

    #endregion

    /// <summary>
    /// Base view model
    /// </summary>
    public abstract class BaseViewModel : DependencyObject, INotifyPropertyChanged
    {
        /// <summary>
        /// Private store for API Client
        /// </summary>
        private ApiClient apiClient;

        /// <summary>
        /// Private store for API RIA Context
        /// </summary>
        private ApiRiaContext apiContext;

        /// <summary>
        /// Private store for Geocode Client
        /// </summary>
        private GeocodeServiceClient geocodeClient;

        /// <summary>
        /// Private store for Literals
        /// </summary>
        private StreetCare literals;

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Gets the literals.
        /// </summary>
        /// <value>The literals.</value>
        public StreetCare Literals
        {
            get
            {
                return this.literals ?? (this.literals = LiteralsHelper.Literals);
            }
        }

        /// <summary>
        /// Gets the API client.
        /// </summary>
        /// <value>The API client.</value>
        protected ApiClient ApiClient
        {
            get
            {
                return this.apiClient ?? (this.apiClient = new ApiClient());
            }
        }

        /// <summary>
        /// Gets the API RIA Context.
        /// </summary>
        /// <value>The API RIA Context.</value>
        protected ApiRiaContext ApiContext
        {
            get
            {
                return this.apiContext ?? (this.apiContext = new ApiRiaContext());
            }
        }

        /// <summary>
        /// Gets the geocode client.
        /// </summary>
        /// <value>The geocode client.</value>
        protected GeocodeServiceClient GeocodeClient
        {
            get
            {
                return this.geocodeClient ?? (this.geocodeClient = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"));
            }
        }

        /// <summary>
        /// Raises the property changed.
        /// </summary>
        /// <param name="property">The property.</param>
        protected void RaisePropertyChanged(string property)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
    }
}
